package com.ruoyi.web.controller.prt;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.prt.domain.PrtEpLog;
import com.ruoyi.prt.domain.vo.PrtEpLogVO;
import com.ruoyi.prt.domain.vo.PrtPrintLogVO;
import com.ruoyi.prt.service.IPrtEpLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 钱包使用记录Controller
 *
 * @author xiaobo Yan
 * @date 2021-03-31
 */
@RestController
@RequestMapping("/prt/eplog")
public class PrtEpLogController extends BaseController
{
    @Autowired
    private IPrtEpLogService prtEpLogService;

    /**
     * 查询钱包使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrtEpLog prtEpLog)
    {
        startPage();
        List<PrtEpLog> list = prtEpLogService.selectPrtEpLogList(prtEpLog);
        return getDataTable(list);
    }

    /**
     * 导出钱包使用记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:log:export')")
    @Log(title = "钱包使用记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PrtEpLog prtEpLog)
    {
        List<PrtEpLog> list = prtEpLogService.selectPrtEpLogList(prtEpLog);
        ExcelUtil<PrtEpLog> util = new ExcelUtil<PrtEpLog>(PrtEpLog.class);
        return util.exportExcel(list, "log");
    }

    /**
     * 获取钱包使用记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:log:query')")
    @GetMapping(value = "/{epLogId}")
    public AjaxResult getInfo(@PathVariable("epLogId") String epLogId)
    {
        return AjaxResult.success(prtEpLogService.selectPrtEpLogById(epLogId));
    }

    /**
     * 新增钱包使用记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:add')")
    @Log(title = "钱包使用记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrtEpLog prtEpLog)
    {
        return toAjax(prtEpLogService.insertPrtEpLog(prtEpLog));
    }

    /**
     * 修改钱包使用记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:edit')")
    @Log(title = "钱包使用记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrtEpLog prtEpLog)
    {
        return toAjax(prtEpLogService.updatePrtEpLog(prtEpLog));
    }

    /**
     * 删除钱包使用记录
     */
    @PreAuthorize("@ss.hasPermi('system:log:remove')")
    @Log(title = "钱包使用记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{epLogIds}")
    public AjaxResult remove(@PathVariable String[] epLogIds)
    {
        return toAjax(prtEpLogService.deletePrtEpLogByIds(epLogIds));
    }

    /**
     * 查询钱包使用记录列表
     */
    @GetMapping("/getEpLog")
    @Log(title = "查询钱包使用记录列表", businessType = BusinessType.SELECT)
    @PreAuthorize("@ss.hasRole('mobile')")
    public AjaxResult getEpLog(PrtEpLogVO prtEpLogVO)
    {
        prtEpLogVO.setUser(SecurityUtils.getUserId());
        return AjaxResult.success(prtEpLogService.selectPrtEpLogList(prtEpLogVO));
    }
}
